home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9745 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  46 lines

  1. Path: wittgenstein.flingern.de!not-for-mail
  2. From: mackenb@uni-duesseldorf.de (Georg Mackenbrock)
  3. Newsgroups: comp.lang.c++
  4. Subject: how to use fstreams
  5. Date: 3 Mar 1996 22:30:06 GMT
  6. Organization: home
  7. Message-ID: <4hd6he$49c@wittgenstein.flingern.de>
  8. NNTP-Posting-Host: modem8.rz.uni-duesseldorf.de
  9. Keywords: streams
  10. X-Newsreader: TIN [UNIX 1.3 BETA-950824-color PL0]
  11.  
  12. Consider the following C-code:
  13.  
  14. #include <g++/fstream.h>
  15.  
  16. int main(void)
  17.         ofstream out("stream");
  18.         int i=10,j=20,k=30;  
  19.  
  20.         out.setf(ios::bin);     
  21.         out<<i<<j<<k;           // (7)
  22.         out.flush();
  23.         
  24.         ifstream in("stream");
  25.         in.setf(ios::bin);      
  26.         in>>i>>j>>k;               // (12)
  27.         cout<<"i: "<<i<<" j: "<<j<<" k:"<<k<<"\n"; // (13)
  28. }
  29.  
  30. Why is the output in (13):    i: 102030 j: 20 k:30  and not i: 10 j: 20 k: 30 ?
  31.                               ====================          =================
  32.  
  33. Using setf(ios::bin) should put the stream in binary-mode? Or is it not
  34. possible to use "<<" to produce binary files?
  35.  
  36. BTW, I know that I get the correct output, if line (7) is replaced by:
  37.  
  38. (7') out<<i<<" "<<j<<" "<<k;
  39.  
  40. but the stream is still a text-stream.
  41.  
  42. Georg.
  43.  
  44. (Mail: mackenb@uni-duesseldorf.de)
  45.